package week07.necessary.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 数据源枚举
 */
@Getter
@RequiredArgsConstructor
public enum DatasourceEnums {
    WRITE("write"),
    READ("read");

    /** 数据名字*/
    private final String name;

    @Override
    public String toString() {
        return this.name;
    }

    /**
     * 自定义枚举实例化
     * @param name 枚举名
     * @return
     */
    public static DatasourceEnums getInstance(String name) {
        for (DatasourceEnums value : values()) {
            if (value.name.equals(name)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Can't instance enum by " + name);
    }
}
